package com.work.demo.utils;

import com.work.demo.entity.UserDto;

public class UserThradLocal {

    private UserThradLocal(){}


    private static final ThreadLocal<UserDto> USER_INFO_THREAD_LOCAL = new ThreadLocal<>();


    /**
     * 清除用户信息
     */
    public static void clear(){
        USER_INFO_THREAD_LOCAL.remove();
    }

    /**
     * 存储用户信息
     * @param userDto 用户信息
     */
    public static void set(UserDto userDto){
        USER_INFO_THREAD_LOCAL.set(userDto);
    }

    /**
     * 获取当前用户信息
     * @return 当前用户信息
     */
    public static UserDto getCurrentUser(){
        return USER_INFO_THREAD_LOCAL.get();
    }
}
